/* *
 * @file    hal_adc.h
 * @author  Azolla (1228449928@qq.com)
 * @brief   
 * @version 0.1
 * @date    2022-09-19
 * 
 * @copyright Copyright (c) 2022
 * */
#ifndef __HAL_ADC__
#define __HAL_ADC__

#define CONFIG_ADC_AUDIO_ENABLE     1   // 1: ADC Audio.    

typedef struct {
#if CONFIG_ADC_AUDIO_ENABLE
#define AUDIO_BUFF_SIZE   (2 * 320)
    uint8_t *buff;
    uint16_t size;
#else 
    uint16_t buff[128];
    uint16_t size;
    uint16_t average;  // 平均值
    uint16_t volt;     // 电压值
#endif
} adc_val_t;

#include "esp_heap_caps.h"
// #define ADC_MEMORY_CAPS_TYPE      (MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT | MALLOC_CAP_DMA)  // PSRAM
#define ADC_MEMORY_CAPS_TYPE         (MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT | MALLOC_CAP_DMA)     // RAM
#define adc_memory_malloc(size)      heap_caps_malloc(size, ADC_MEMORY_CAPS_TYPE)
#define adc_memory_calloc(n, size)   heap_caps_calloc(n, size, ADC_MEMORY_CAPS_TYPE)
#define adc_memory_realloc(size)     heap_caps_realloc(ptr, size, ADC_MEMORY_CAPS_TYPE)
#define adc_memory_free(ptr)         heap_caps_free(ptr)

void hal_adc_init(void);

void adc_read_start(void);

void adc_read_start_once(void);

void adc_read_stop(void);
 
bool adc_read_buff(adc_val_t *val, uint32_t wait_timeout);

#endif /* __HAL_ADC__ END. */

